import base64

s = b"test a str"
b64 = base64.b64encode(s)
print(b64)

s = base64.b64decode(b'dGVzdCBhIHN0cg==')
print(s)